<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>刷步数小工具</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="css/style.css">
</head>
<body>
    <?php include 'includes/navbar.php'; ?>
    <div class="container mt-5">
        <div class="card">
            <h2 class="mb-4 text-center">小米运动刷步数小工具</h2>
            <form id="updateStepsForm">
                <div class="mb-3">
                    <label for="user" class="form-label">账号</label>
                    <input type="text" class="form-control" id="user" name="user" required>
                </div>
                <div class="mb-3">
                    <label for="password" class="form-label">密码</label>
                    <input type="password" class="form-control" id="password" name="password" required>
                </div>
                <div class="mb-3">
                    <label for="step" class="form-label">步数</label>
                    <input type="number" class="form-control" id="step" name="step" required>
                </div>
                <button type="submit" class="btn btn-primary w-100">更新步数</button>
            </form>
            <div id="result" class="mt-3"></div>
        </div>
        <div class="card mt-5">
            <h3 class="mb-4 text-center">使用说明</h3>
            <ol class="list-group list-group-flush">
                <li class="list-group-item">下载并安装 <strong>Zepp Life</strong> 应用。</li>
                <li class="list-group-item">使用邮箱注册账号，邮箱可以随意填写。</li>
                <li class="list-group-item">在应用中绑定第三方平台（如微信、支付宝等），选择你想要刷步数的平台。</li>
            </ol>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script src="js/script.js"></script>
    <script>
        document.getElementById('updateStepsForm').addEventListener('submit', function(event) {
            event.preventDefault();
            var user = document.getElementById('user').value;
            var password = document.getElementById('password').value;
            var step = document.getElementById('step').value;

            fetch('https://xzdx.top/api/yzmb', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded'
                },
                body: 'user=' + encodeURIComponent(user) + '&password=' + encodeURIComponent(password) + '&step=' + encodeURIComponent(step)
            })
            .then(response => response.json())
            .then(data => {
                if (data.code === 0) {
                    document.getElementById('result').innerHTML = '<div class="alert alert-success" role="alert">步数更新成功！</div>';
                } else {
                    document.getElementById('result').innerHTML = '<div class="alert alert-danger" role="alert">' + data.msg + '</div>';
                }
            })
            .catch(error => {
                document.getElementById('result').innerHTML = '<div class="alert alert-danger" role="alert">更新失败: ' + error + '</div>';
            });
        });
    </script>
</body>
</html>